/* 
 * File:   Player.cpp
 * Author: Pouja
 * 
 * Created on 24 juli 2012, 14:00
 */

#include "Player.h"
#include "Hand.h"

const int Player::MAX_LEVEL=3;

map<int, int> createMapLevel() {
    map<int,int> m;
    m.insert(map<int, int>::value_type(1, 100));
    m.insert(map<int, int>::value_type(2, 200));
    m.insert(map<int, int>::value_type(3, 300));
    return m;
}

Player::Player(string n) {
    name = n;
    level = 1;
    xp = 0;
    wins = 0;
    losses = 0;
    deck = NULL;
    field = NULL;
    hasTurn = false;
    opponent = NULL;
    hand = new Hand();
    mapLevel = createMapLevel();
}

Player::Player(string n, int lvl, int x, int w, int l, Deck *d) {
    name = n;
    level = lvl;
    xp = x;
    wins = w;
    losses = l;
    deck = d;
    hasTurn = false;
    field = NULL;
    hand = new Hand();
    mapLevel = createMapLevel();
}

void Player::setName(string n) {
    name = n;
}

string Player::getName() {
    return name;
}

void Player::setLevel(int lvl) {
    level = lvl;
}

int Player::getLevel() {
    return level;
}

void Player::setXp(int x){
    xp = x;
}

int Player::getXp() {
    return xp;
}

void Player::setWins(int w){
    wins = w;
}

int Player::getWins() {
    return wins;
}

void Player::setLosses(int l) {
    losses = l;
}

int Player::getLosses() {
    return losses;
    
}

void Player::setDeck(Deck *d) {
    deck = d;
}

Deck* Player::getDeck() {
    return deck;
}

void Player::setField(Field *f) {
    field = f;
}

Field* Player::getField() {
    return field;
}

void Player::setHasTurn(bool b) {
    hasTurn = b;
}

bool Player::getHasTurn() {
    return hasTurn;
}

void Player::setOpponent(Player *p) {
    opponent = p;
}

Player* Player::getOpponent() {
    return opponent;
}

void Player::addWin() {
    wins++;
}

void Player::addLoss() {
    losses++;
}

void Player::addXp(int x){
    assert(x > 0);
    if(level == Player::MAX_LEVEL){
        xp += x;
    }
    else{
        int diff = xp + x - mapLevel[level];

        if (diff == 0) {
            level++;
            xp = 0;
        } else if (diff > 0) {
            level++;
            xp = 0;
            addXp(diff);
        } else {
            xp += x;
        }
    }
}

bool Player::firstToGo() {
    string choice;
    cout << "Do you want to go first " << name << "? (y/n) ..." << endl;
    cin >> choice;
    
    if (choice == "y") return true;
    
    return false;
}

<<<<<<< .mine
void Player::drawCard() {
    hand->addCard(field->getDeckZone()->removeCard());
}

void Player::setHand(Hand* hd){
    assert(hd != NULL);
    hand=hd;
}

Hand* Player::getHand(){
    return hand;
}

void placeMonsterCard(MonsterCard* card, bool face, bool stance){
    
}

void placeSpellCard(SpellTrapCard* card, bool face){
    
}

void placeTrapCard(SpellTrapCard* card){
    
}

void summon(MonsterCard* card){
    
}
void tributeSummon(MonsterCard* card, MonsterCard* card2){
    
}

void tributeSummon(MonsterCard* card, MonsterCard* card2, MonsterCard* card3){
    
}

/*void xyzSummon(XyzMonsterCard,bool){
    
}

void synchroSummon(SynchroMonsterCard,TunerMonsterCard,MonsterCard[],bool){
    
=======
void placeMonsterCard(MonsterCard* card, bool face, bool stance){
    
}

void placeSpellCard(SpellTrapCard* card, bool face){
    
}

void placeTrapCard(SpellTrapCard* card){
    
}

void summon(MonsterCard* card){
    
}
void tributeSummon(MonsterCard* card, MonsterCard* card2){
    
}

void tributeSummon(MonsterCard* card, MonsterCard* card2, MonsterCard* card3){
    
}

/*void xyzSummon(XyzMonsterCard,bool){
    
}

void synchroSummon(SynchroMonsterCard,TunerMonsterCard,MonsterCard[],bool){
    
}

void fusionSummon(FusionMonsterCard,bool){
    
}*/

void set(MonsterCard* card){
    
}

void tributeSet(MonsterCard* card, MonsterCard* card2){
    
}

void tributeSet(MonsterCard* card, MonsterCard* card2, MonsterCard* card3){
    
}

void attack(Card cardSelect, Card cardTarget){
    
>>>>>>> .r45
}

<<<<<<< .mine
void fusionSummon(FusionMonsterCard,bool){
    
}*/
=======
void nextPhase(){
    
}
>>>>>>> .r45

<<<<<<< .mine
void set(MonsterCard* card){
    
}

void tributeSet(MonsterCard* card, MonsterCard* card2){
    
}

void tributeSet(MonsterCard* card, MonsterCard* card2, MonsterCard* card3){
    
}

void attack(Card cardSelect, Card cardTarget){
    
}

void nextPhase(){
    
}

/*void selectPhase(Phase){
    
}*/

void surrender(){
    
}
=======
/*void selectPhase(Phase){
    
}*/

void surrender(){
    
}
>>>>>>> .r45

bool Player::operator ==(const Player &other) {
    return (name == other.name);
}

bool Player::operator !=(const Player &other) {
    return !(*this == other);
}

string Player::toString() {
    string output;
    stringstream ss;
    ss << name << " (" << level << ", " << xp << "/" << mapLevel[level] << ", " << wins << " wins, " << losses << " losses)";
    output = ss.str();

    return output;
}

ostream& operator <<(ostream &output, const Player &p) {
    output << p.name << " (" << p.level << ", " << p.xp << "/" 
             
            << p.mapLevel.find(p.level)->second //at is geen standaard functie, daarom heb ik at vervangen met find
            << ", " << p.wins << " wins, " << p.losses << " losses)";
    return output;
}

Player::~Player() {
    delete deck;
    delete field;
}
